package kg.aibek.projecteuler.p10;

public class Problem36 {
	public void solve() {
		long sum = 0;
		for (int i = 1; i < 1000000; i += 2) {
			if (isPalindrome(i + "") && binary(i)) {
				System.out.println(i);
				sum += i;
			}
		}

		System.out.println("--- " + sum);
	}

	private boolean binary(int number) {
		StringBuilder sb = new StringBuilder();
		while (number > 0) {
			sb.append(number % 2);
			number = number / 2;
		}

		String str = sb.toString();
		return str.equals(sb.reverse().toString());
	}

	private boolean isPalindrome(String str) {
		StringBuilder sb = new StringBuilder();
		sb.append(str);
		sb.reverse();
		return sb.toString().equals(str);
	}

	public static void main(String[] args) {
		Problem36 p = new Problem36();
		p.solve();
	}
}
